package com.harmontronics.hanma.paas.paas.controller;

import cn.hutool.core.convert.Convert;
import com.harmontronics.hanma.paas.paas.annotation.Log;
import com.harmontronics.hanma.paas.paas.common.PageBase;
import com.harmontronics.hanma.paas.paas.common.ResponseEntity;
import com.harmontronics.hanma.paas.paas.domain.app.entity.HmEntityModel;
import com.harmontronics.hanma.paas.paas.dto.input.IdInput;
import com.harmontronics.hanma.paas.paas.dto.output.HmEntityModelResult;
import com.harmontronics.hanma.paas.paas.service.HmPublishedEntityModelAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 模型版本字段信息
 *
 * @author paas-generator
 * @email paas-generator@harmontronics.com
 * @date 2021-05-11 09:54:52
 * @since v1.1-sprint1
 */
@RestController
@RequestMapping("/api/hm-published-entity-model")
@Api(tags = {"模型版本字段信息"})
public class HmPublishedEntityModelController {
    @Autowired
    private HmPublishedEntityModelAppService hmPublishedEntityModelappService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation("列表")
    public ResponseEntity<List<HmEntityModelResult>> list(@RequestParam Long publishId) {
        List<HmEntityModel> hmPublishedEntityModelList = hmPublishedEntityModelappService.getList(publishId);
        return ResponseEntity.ok(Convert.toList(HmEntityModelResult.class, hmPublishedEntityModelList));
    }

    /**
     * 分页列表
     */
    @GetMapping("/page/list")
    @ApiOperation("分页列表")
    public ResponseEntity<PageBase<HmEntityModelResult>> list(@ApiParam(value = "发布ID") @RequestParam Long publishId,
                                                              @ApiParam(value = "模型ID") @RequestParam(required = false) Long modelId,
                                                              @ApiParam(value = "是否隐藏系统字段") @RequestParam(required = false,defaultValue = "false") boolean hiddenSystemField,
                                                              @ApiParam(value = "页码", defaultValue = "1") @RequestParam(required = false, defaultValue = "1") int pageNo,
                                                              @ApiParam(value = "每页数据条数", defaultValue = "20") @RequestParam(required = false, defaultValue = "20") int pageSize) {
        PageBase<HmEntityModel> hmPublishedEntityModelPageBase = hmPublishedEntityModelappService.getList(modelId, publishId,hiddenSystemField, pageNo, pageSize);
        PageBase<HmEntityModelResult> resultPageBase = PageBase.copy(hmPublishedEntityModelPageBase, HmEntityModelResult.class);
        return ResponseEntity.ok(resultPageBase);
    }


    @PutMapping("/move-up")
    @ApiOperation(value = "上移")
    @Log("上移了模型字段")
    public ResponseEntity moveUp(@RequestBody IdInput moveData) {
        hmPublishedEntityModelappService.up(moveData.getId());
        return ResponseEntity.ok();
    }

    @PutMapping("/move-down")
    @ApiOperation(value = "下移")
    @Log("下移了模型字段")
    public ResponseEntity moveDown(@RequestBody IdInput moveData) {
        hmPublishedEntityModelappService.down(moveData.getId());
        return ResponseEntity.ok();
    }

}
